package com.hjwei.lru;

import java.util.LinkedHashMap;
import java.util.Map;

public class SimpleLRUCache extends LinkedHashMap<Integer,Integer> {

        private int capacity;

    public SimpleLRUCache(int initialCapacity, int capacity) {
        super(initialCapacity);
        this.capacity = capacity;
    }

    public int get(int key){
        return super.getOrDefault(key,-1);
    }

    public void put(int key,int value){
        super.put(key,value);
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<Integer, Integer> eldest) {
        return size()>capacity;
    }
}
